
import 'package:flutter/cupertino.dart';
import 'package:image_picker/image_picker.dart';


class GetImageOrVideo {
  static ImagePicker _picker = ImagePicker();

  //获取视频
  static Future getVideo({
    required ImageSource source,//相机,相册
    CameraDevice? preferredCameraDevice,
    Duration? maxDuration,//最大时长
  }) async {
    if (source == null) {
      source = ImageSource.gallery;
    }
    if (preferredCameraDevice == null) {
     preferredCameraDevice = CameraDevice.rear;
    }
    if (maxDuration == null) {
      maxDuration = Duration(seconds: 300);
    }

   final pickedFile  =await _picker.getVideo(
      source: source,
      preferredCameraDevice: preferredCameraDevice,
      maxDuration: maxDuration,
    );
    return pickedFile;
  }

  //获取照片
  static Future<PickedFile?> getImage({
    required ImageSource imageSource, //相机，相册
    double? maxWidth, //宽
    double? maxHeight, //高
    int? imageQuality, //0-100 相片质量
    CameraDevice? preferredCameraDevice,
  } //前后摄像头
      ) async {
    if (imageSource == null) {
      imageSource = ImageSource.gallery;
    }
    if (maxWidth == null) {
//      maxWidth = SizeFill.setRx(80);
    }
    if (maxHeight == null) {
//      maxHeight = SizeFill.setRx(80);
    }
    if (imageQuality == null) {
      imageQuality = 100;
    }
    if (preferredCameraDevice == null) {
      preferredCameraDevice = CameraDevice.rear;
    }

    final pickerFile = await _picker.getImage(
      source: imageSource,
      maxHeight: maxHeight,
      maxWidth: maxWidth,
      preferredCameraDevice: preferredCameraDevice,
      imageQuality: imageQuality,
    );
    return pickerFile;
  }
}
